package com.example.boos.stores.money;

import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;


import com.example.boos.R;
import com.example.boos.context.BossInfo;
import com.example.boos.pojo.Orders;

import java.util.List;

public class BillsItemAdapter  extends RecyclerView.Adapter<BillsItemAdapter.VH> {

    private balance_main act;

    private List<Orders> orders;
    private Float myAllMoney;

    public BillsItemAdapter(balance_main act,List<Orders> orders){
        this.act = act;
        this.orders = orders;
        myAllMoney = BossInfo.boss.getMoney();
    }

    public void updateAll(List<Orders> data){
        orders = data;
        notifyDataSetChanged();
    }


    @NonNull
    @Override
    public VH onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = View.inflate(act, R.layout.balance_bill_item,null);
        VH viewHolder = new VH(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull VH holder, int position) {
        Orders order = orders.get(position);
        // 设置数据
        holder.content.setText("订单-"+order.getId());
        holder.allMoney.setText(myAllMoney.toString());
        myAllMoney -= order.getTotalPrice();
        holder.addMoney.setText("+"+order.getTotalPrice());
        holder.time.setText(order.getEndTime().toString());

        /*
        * 绑定监听事件
        * */
    }

    @Override
    public int getItemCount() {
        return orders.size();
    }

    class VH extends RecyclerView.ViewHolder{

        private TextView content;
        private TextView addMoney;
        private TextView time;
        private TextView allMoney;

        public VH(@NonNull View itemView) {
            super(itemView);
            content = itemView.findViewById(R.id.bill_item_content);
            addMoney = itemView.findViewById(R.id.bill_item_addMoeny);
            time = itemView.findViewById(R.id.bill_item_time);
            allMoney = itemView.findViewById(R.id.bill_item_money);
        }
    }
}
